
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.media.*;
import javafx.ext.swing.SwingButton;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Slider;
import javafx.scene.control.TextBox;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.layout.Flow;
import javafx.scene.Group;
import javafx.animation.Timeline;
import javafx.scene.control.Hyperlink;
import java.lang.System;
import javax.swing.JFileChooser;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.geometry.*;



/**
 * @author goemb
 */


var player:MyMediaPlayer = MyMediaPlayer {
    movieWidth: bind scene.width * 0.75;
    movieHeight: bind scene.height * 0.8;
}

def slider = Slider {
	value: 75
   	max: 100
}

var brightSlider = Slider {
	vertical: true
	value: 75
   	max: 100
}

var play_1 = Image {
    url: "file:///Users/goemb/Documents/multimedia1/buttons/play_1.png"
    width: 40
    preserveRatio: true
}
var play_2 = Image {
    url: "file:///Users/goemb/Documents/multimedia1/buttons/play_2.png"
    width: 40
    preserveRatio: true
}
var play_3 = Image {
    url: "file:///Users/goemb/Documents/multimedia1/buttons/play_3.png"
    width: 40
    preserveRatio: true
}
var open_1 = Image {
    url: "file:///Users/goemb/Documents/multimedia1/buttons/open_1.png"
    width: 40
    preserveRatio: true
}
var center_1 = Image {
    url: "file:///Users/goemb/Documents/multimedia1/buttons/center_1.png"
    width: 50
    preserveRatio: true
}
var shake_1 = Image {
    url: "file:///Users/goemb/Documents/multimedia1/buttons/shake_1.png"
    width: 50
    preserveRatio: true
}


var controlsGroup:Group = Group {
    content: [
    	HBox {
			height: bind scene.width * 0.1
	   		content: [
	   			VBox {
   				  	width: bind scene.width * 0.3
   				   	content: [
   						ImageView {
   					   	image: open_1
	   					   	onMouseClicked: function( e: MouseEvent ): Void {
	   					   		println("OPEN FILE");
	   					   		println(stage.width);
	   					   		println(stage.height);
	   					   		isVisible = not isVisible;
	   					   	}
   					   	}
   					]	   				
   				}
				VBox {
	   			    hpos: HPos.CENTER
	   			    width: bind scene.width * 0.2
	   			    content: [
		           		ImageView {
   					   	image: play_1
	   					   	onMouseClicked: function( e: MouseEvent ): Void {
	   					   		println("PLAY");
	   					   	}
   					   	}
		   			]	   				
	   			}
	   			VBox {
	   			    width: bind scene.width * 0.3
	   			    hpos: HPos.RIGHT
		   			content: [
			    		Label {text: "Volume"}
		        		slider
		        	]
	   			}
	   			
           	]
        }
	]
}


var fileBox:TextBox = TextBox{}
var isVisible:Boolean = false;

var openControlsGroup:Group = Group {
    content: [
		HBox {
  			height: bind scene.width * 0.1
   			visible: bind isVisible
   			content: [
   				Label { text: "URL/FILE: "},
   				fileBox,
   				SwingButton {
   					text: "searchFile"
   				   	action: function() {
   				  		println("Search File");
   				     	var chooser = new JFileChooser();
   				       	if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
   				         	fileBox.text = chooser.getSelectedFile().toURI().toString();
   				       	}
   				 	}
   				}
   			SwingButton {
   				text: "Load"
   				action: function() {
   				   	println("Load");
   				  	player.setVideo(fileBox.text);
   				   	isVisible = false;
   				}
   			}
   		]
	} 
    ]
}

def scene: Scene = Scene {
       content: 
          VBox {
                content: [
                	HBox {
                    	content: [
                    		VBox { 
                    		    width: bind scene.width * 0.8
                                content: [
									VBox {
										height: bind scene.height * 0.7
										content: [
	                                		player
										]
									}
									VBox {
										height: bind scene.height * 0.3
										vpos: VPos.BOTTOM
										content: [
		                            		controlsGroup,
				                            openControlsGroup
										]
									}
	                            ]
                        	},
                            VBox {
                                //width: 50
								hpos: HPos.RIGHT
                            	content: [
									HBox {
										height: bind scene.height * 0.18
										width: bind scene.width * 0.15
										hpos: HPos.CENTER
										content: [
											VBox {
												content: [
        	                     					Label {text: "Start:"}
				        	                       	TextBox {} 
				        	                     	Label {text: "Dauer:"}
				        	                       	TextBox {} 
												]
	 										}
										]
									}
   				                    HBox {
										height: bind scene.height * 0.12
										width: bind scene.width * 0.15
										hpos: HPos.CENTER
										content: [
											ImageView {
					   					   	image: center_1
						   					   	onMouseClicked: function( e: MouseEvent ): Void {
						   					   		println("CENTER");
						   					   	}
					   					   	}	
										]
									}
									HBox {
										height: bind scene.height * 0.12
										width: bind scene.width * 0.15	
										hpos: HPos.CENTER
										content: [
											ImageView {
					   					   	image: shake_1
						   					   	onMouseClicked: function( e: MouseEvent ): Void {
						   					   		println("SHAKE");
						   					   	}
					   					   	}	
										]
									}
									VBox {
										height: bind scene.height * 0.3
										content: [
											HBox {
												width: bind scene.width * 0.15
												vpos: VPos.CENTER
												hpos: HPos.CENTER
												content: [
													Label {text: "Brightness"}
												]
											}
											HBox {
												rotate: 180
												width: bind scene.width * 0.15
												hpos: HPos.CENTER
												content: [
									        		brightSlider
												]
											}
										]
									}  	                       	       	                       	
                                ]
                           	}
                       	]
					} 
				]
          }
          fill: Color.LIGHTGRAY         
     }//Scene
 
def stage:Stage = Stage {
    title: "MediaPlayer MM1"
    width: bind stageWidth with inverse
    height: bind stageHeight with inverse
    scene: scene
}

var stageWidth = stage.width on replace {
	if (stageWidth < 640) stageWidth = 640;	
}

var stageHeight = stage.height on replace {
	if (stageHeight < 480) stageHeight = 480;	
}